import FieldsUtils from '@/utils/fields';

// 转换配置数据为 FieldProps 格式
const convertToFieldProps = (configData: any[]): FieldProps[] => {
  return configData.map((item: any) => ({
    ...item,
    // 确保 required 字段是 number 类型
    required: typeof item.required === 'boolean' ? (item.required ? 1 : 0) : item.required,
  }));
};

// 处理表格字段
const getTableFieldsList = (fields: any[], type: string) => {
  // 转换字段为正确的 FieldProps 格式
  const convertedFields = convertToFieldProps(fields);

  const custom = {};
  let _fields = FieldsUtils.getColumns(convertedFields, custom);
  _fields = FieldsUtils.filterByType(_fields, type);
  return _fields;
};

export { getTableFieldsList };
